#include <stdio.h>

void quicksort(int *arr,int l,int h){
    int pivot = arr[h];
    int i = l;
    for (int j=l;j<h;j++){
        if (arr[j]<pivot){
            int temp = arr[j];
            arr[j] = arr[i];
            arr[i] = temp;
            i++;
        }
    }
    arr[h] = arr[i];
    arr[i] = pivot;
    
    if(i-1>l){quicksort(arr,l,i-1);}
    if(i+1<h){quicksort(arr,i+1,h);}

}

int main(){
    int arr[] = {8,4,1,3,2,7,5,9,6};
    int arr_long = sizeof(arr)/sizeof(arr[0]);
    quicksort(arr,0,arr_long-1);
    // 输出排序后的数组
    for (int i=0;i<arr_long;i++){printf("%d ",arr[i]);}
    return 0;
}
/* 划分操作：
8 4 1 3 2 7 5 9 6
以5为枢纽
8 4 1 3 2 7 5 9 6
4]8 1 3 2 7 5 9 6
4 1]8 3 2 7 5 9 6
4 1 3]8 2 7 5 9 6
4 1 3 2]8 7 5 9 6

*/
